package 基础;

import org.junit.Test;

/**
 * Create with IDEA
 * author:yangyangkun
 * Date:2019/4/12
 * Time:17:55
 */
public class StringT {
    //String是引用类型变量
    //System.identityHashCode()      获取对象地址的方法
    @Test
    public void test1(){
        String str1 = "aa";
        String str2 = "aa";
        System.out.println("str1 == str2 :" + (str1 == str2));
        System.out.println("str1的地址：" + System.identityHashCode(str1));
        System.out.println("str2的地址：" + System.identityHashCode(str2));
        System.out.println("----------------------------------------------------" );
        String str3 = "aa";
        String str4 = new String("aa");
        System.out.println("str3 == str4 :" + (str3 == str4));
        System.out.println("str3的地址：" + System.identityHashCode(str3));
        System.out.println("str4的地址：" + System.identityHashCode(str4));
        str2 = str2 + " ";
        System.out.println("str2的地址是：" + System.identityHashCode(str2) + "发生了改变");
        //在test1方法 内存一共存在了 3 个变量，想想为什么是三个
    }


}
